package com.zhisheng.demo03_Stream_Hello;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 创建者： 智晟全哥
 */
public class MyHello {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Collections.addAll(list,"张三丰","张翠山","张三","张无忌","赵敏敏");
        List<String> list1 = method1(list);
        List<String> list2 = method2(list);
        System.out.println(list1);
        System.out.println(list2);

    }

    private static List<String> method2(List<String> list) {
        // 1: 获取Stream,面向流对象,调用方法,完成功能
        return list.stream().filter(s->s.startsWith("张") && s.length() == 3).toList();
    }

    private static List<String> method1(List<String> list) {
        // 遍历,判断,收集
        List<String> list1 = new ArrayList<>();
        // 遍历
        list.forEach(s->{
            // 判断
            if(s.startsWith("张") && s.length() == 3){
                // 收集
                list1.add(s);
            }
        });
        return list1;

    }
}
